﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using W.Common.Enum;
using W.Warehouse.Domain.DTO;
using W.Warehouse.Read.Api.Application.Command.AllocationCommand;
using W.Warehouse.Read.Api.Application.Command.CheckCommand;

namespace W.Warehouse.Read.Api.Controllers
{
    /// <summary>
    /// 盘点控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CheckController : ControllerBase
    {
        private readonly IMediator _mediator;
        private readonly ILogger<CheckController> _logger;
        public CheckController(IMediator mediator, ILogger<CheckController> logger)
        {
            _mediator = mediator;
            _logger = logger;
        }
        /// <summary>
        /// 单据类型
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public dynamic GetAuditStatus()
        {
            return Enum.GetValues(typeof(AuditStatus))
                .Cast<AuditStatus>()
                .Select(x => new
                {
                    Value = (int)x,
                    Text = x.ToString()
                }).ToList();
        }
        /// <summary>
        /// 盘点列表显示
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDTO<CheckShowDTO>>> GetAllocationList([FromQuery] CheckShowCommand command)
        {
            ApiResult<PageDTO<CheckShowDTO>> result = new ApiResult<PageDTO<CheckShowDTO>>();
            try
            {
                //var uid=HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;//获取用户id
                //var sid = HttpContext.User.FindFirst(JwtRegisteredClaimNames.Sid)?.Value;//获取公司id
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 盘点反填
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<StatisticModelDTo>> GetCheckModel([FromQuery] StatisticsModelCommand command)
        {
            ApiResult<StatisticModelDTo> result = new ApiResult<StatisticModelDTo>();
            try
            {
                //var uid=HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value;//获取用户id
                //var sid = HttpContext.User.FindFirst(JwtRegisteredClaimNames.Sid)?.Value;//获取公司id
                result.Data = await _mediator.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
    }
}
